package com.bootdo.lvyou.service.impl;

import com.bootdo.common.utils.StringUtils;
import com.front.web.commons.RRException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.bootdo.lvyou.dao.LvyouMemberDao;
import com.bootdo.lvyou.domain.LvyouMember;
import com.bootdo.lvyou.service.LvyouMemberService;



@Service
public class LvyouMemberServiceImpl implements LvyouMemberService {
	@Autowired
	private LvyouMemberDao lvyouMemberDao;
	
	@Override
	public LvyouMember get(Long id){
		return lvyouMemberDao.get(id);
	}
	
	@Override
	public List<LvyouMember> list(Map<String, Object> map){
		return lvyouMemberDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return lvyouMemberDao.count(map);
	}
	
	@Override
	public int save(LvyouMember lvyouMember){
	
		if(lvyouMember.getId() != null) {
			return lvyouMemberDao.update(lvyouMember);
		}else {
			return lvyouMemberDao.save(lvyouMember);
		}		
	
		
	}
	
	@Override
	public int update(LvyouMember lvyouMember){
		return lvyouMemberDao.update(lvyouMember);
	}
	
	@Override
	public int remove(Long id){
		return lvyouMemberDao.remove(id);
	}
	
	@Override
	public int batchRemove(Long[] ids){
		return lvyouMemberDao.batchRemove(ids);
	}

	@Override
	public LvyouMember getByOpenid(String openid) {
		return lvyouMemberDao.getByOpenid(openid);
	}

	@Override
	public LvyouMember getByMobile(String mobile) {
		return lvyouMemberDao.getByMobile(mobile);
	}

	@Override
	public Map getByIdGetNamePhoto(Long memberId) {
		return lvyouMemberDao.getByIdGetNamePhoto(memberId);
	}

	@Override
	public LvyouMember login(String mobile, String password) {


		LvyouMember member = getByMobile(mobile);
		try {
			if(member==null){
				throw new RRException("您输入的账号不存在！");
			}
			if(member.getIsShow() != null && member.getIsShow().equals(1)) {
				throw new RRException("您的账号已停用！");
			}
			//密码错误
			if(!member.getPassword().equals(DigestUtils.sha256Hex(password))){
				throw new RRException("手机号或密码错误");
			}
			return member;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
